package main;

import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.Collection;

import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.DefaultSymbolFactory;
import java_cup.runtime.SymbolFactory;

public class Query {
	
	
	/*public static <E extends Collection> Collection SELECT(String query, E ... collections){
		return SELECT(query,collections);
	}*/
	
	public static  <T extends Collection> T SELECT(String query, T ... collections) {
			if(collections.length == 0) {
				throw new RuntimeException("Collection array cannot be empty");
			}
			SymbolFactory sf = new ComplexSymbolFactory(); 
			Scanner scanner;
			try {
				scanner = new Scanner(new ByteArrayInputStream(query.getBytes("UTF-8")),sf);
				Parser parser = new Parser(scanner,sf);
				parser.setCollections(collections);
				return (T) parser.parse().value;
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
	}
	
	public static boolean UPDATE(String query,Collection ... collections){
		return true;
	}
}
